<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">我的计分</block>
		</cu-custom>	
		<uni-section title="基本信息" type="line">
			<uni-list>
				<uni-list-item  title="姓名" :rightText="person.name"></uni-list-item>
				<uni-list-item  title="工龄" :rightText="person.workAge"></uni-list-item>
				<uni-list-item  title="总分" :rightText="sum"></uni-list-item>
			</uni-list>
		</uni-section>
		<view v-for="category in categoryList" :key="category.id">
			<uni-section :title="category.name" type="line">
				<view v-for="item in category.list" :key="item.id">
					<uni-card :title="item.name" :extra="item.score">
						<view class=""style="border-bottom: 1px solid #eceae5;">
							<view class="" style="display: flex; position: relative;">
								<view class="slot-box" style="margin-bottom: 8px;">
									<uni-tag :text="item.state == '-1' ? '待提交' : item.state == '1'? '审核中': item.state == '2'? '未审核通过': '审核通过' " :type="item.state == '-1' ? 'default' : item.state == '1'? 'primary': item.state == '2'? 'error':'success' " :circle="true" :inverted="true"></uni-tag>
								</view>
								<view style="position: absolute; top: -2px; right: 10px;">
									<switch :checked="false" color="#ff6d0b" @change="switch1Change(item.id,$event)" />
								</view>
							</view>
						</view>
					</uni-card>
				</view>
				<br/>
			</uni-section>
		</view>
		<br/>
		<button class="myfootbtn" type="primary" @click="upload()">提交审核</button>
		<br/>
	</view>
</template>

<script>
	export default {
		name: "getSum",
		data() {
			return {
				tableData:[],
				person:{
					name: '史蒂文',
					workAge: ' 5',
				},
				sum: "0",
				categoryList: [
					{
						id:	"213236",
						name:"111111111",
						isShow: false,
						list:[
							{
								id: "4354675",
								name: "标准项1",
								score: "10",
								state: "-1",
							},
							{
								id: "43546751",
								name: "标准项2",
								score: "10",
								state: "-1",
							}
						],
						flag:"cuIcon-right text-black",
					},
					{
						id:	"2132367",
						name:"2222222222",
						isShow: false,
						list:[
							{
								id: "43546751",
								name: "标准项1",
								score: "10",
								state: "-1",
							},
							{
								id: "435467511",
								name: "标准项2",
								score: "10",
								state: "-1",
							}
						],
						flag:"cuIcon-right text-black",
					},
					{
						id:	"2132361",
						name:"33333333",
						isShow: false,
						list:[
							{
								id: "43546752",
								name: "标准项1",
								score: "10",
								state: "-1",
							},
							{
								id: "435467512",
								name: "标准项2",
								score: "10",
								state: "-1",
							}
						],
						flag:"cuIcon-right text-black",
					},
					{
						id:	"2132362",
						name:"44444444444",
						isShow: false,
						list:[
							{
								id: "43546753",
								name: "标准项1",
								score: "10",
								state: "1",
							},
							{
								id: "435467513",
								name: "标准项2",
								score: "10",
								state: "-1",
							}
						],
						flag:"cuIcon-right text-black",
					},
					{
						id:	"2132363",
						name:"555555555",
						isShow: false,
						list:[
							{
								id: "43546754",
								name: "标准项1",
								score: "10",
								state: "-1",
							},
							{
								id: "435467514",
								name: "标准项2",
								score: "10",
								state: "2",
							}
						],
						flag:"cuIcon-right text-black",
					},
					{
						id:	"2132364",
						name:"6666666",
						isShow: false,
						list:[
							{
								id: "43546755",
								name: "标准项1",
								score: "10",
								state: "0",
							},
							{
								id: "435467515",
								name: "标准项2",
								score: "10",
								state: "-1",
							}
						],
						flag:"cuIcon-right text-black",
					},
				],
				project_id: "",
				totalItem: {
					"43546755":{
						// id:item.id,
						score: "",
						state: "0",
						flag: false,
					},
					"435467514":{
						// id:item.id,
						score: "",
						state: "2",
						flag: false,
					},
					"435467512":{
						// id:item.id,
						score: "",
						state: "1",
						flag: false,
					},
				},
			}
		},
		onLoad: function () { //option为object类型，会序列化上个页面传递的参数
			console.log(this.$Route.query)
			this.project_id = this.$Route.query.id
		},
		mounted() {
			this.init()
		},
		methods: {
			switch1Change: function (id,e) {
				console.log('switch1 发生 change 事件，携带值为', e,e.detail.value,id)
				if(this.totalItem[id]) {
					switch(this.totalItem[id].state) {
						case "0":
						console.log(0)
						if(e.detail.value) {
							uni.showToast({
								title: "已添加",
								icon: 'none'
							})
							this.totalItem[id].flag = e.detail.value
						}else {
							// console.log(kkkk)
							uni.showToast({
								title: "已取消",
								icon: 'none'
							})
							this.totalItem[id].flag = e.detail.value
						}
						break
						case "1":
						console.log(1)
						uni.showToast({
							title: "该项正在审核中",
							icon: 'none'
						})
						e.detail.value = false
						break
						case "2":
						console.log(2)
						uni.showToast({
							title: "该项资质未通过，请重新提交",
							icon: 'none'
						})
						e.detail.value = false
						break
					}
				}else {
					uni.showToast({
						title: "该项资质没有提交记录",
						icon: 'none'
					})
					e.detail.value = false
				}
			},
			init() {
				this.getCategoryList()
			},
			getSubmitList() {
				this.$http.post(`/base/znzfEmployeeScoreItem/getEmployeeScoreItemList?userId=${this.$store.getters.userid}`).then(res => {
					console.log(5,res.data.result)
					this.totalItem = []
					res.data.result.forEach(item => {
						let temp = {
							// id:item.id,
							score: "",
							state: item.state,
							flag: false,
						}
						for(let category of this.categoryList) {
							for(let c of category.list) {
								if (item.scoreItemId == c.id) c.state = item.state
							}
						}
						this.totalItem[item.id] = temp
					})
					console.log(this.totalItem)
				})
			},
			getCategoryList() {
				this.$http.get(`/base/znzfScoreStandard/list`).then(res => {
					this.categoryList = []
					res.data.result.records.forEach(category => {
						let temp = {
							id: category.id,
							name: category.title,
							isShow: false,
							list: [],
							flag:"cuIcon-right text-black",
						}
						this.$http.get(`/base/znzfScoreStandard/queryZnzfScoreStandardItemByMainId?id=${category.id}`).then(res => {
							res.data.result.forEach((item,index) => {
								let temp1 = {
									id: item.id,
									score: item.score,
									name: item.name,
									state: "-1",
								}
								temp.list.push(temp1)
							})
						})
						this.categoryList.push(temp)
					})
					console.log(this.categoryList)
					this.getSubmitList()
				})
			},
		}
	}
</script>

<style>
.myfabbtn{
	position: fixed;
	left: 8px;
	bottom: 16px;
	border-radius: 50%;
	border: none;
	background-color: #8cde9b;
	width: 50px;
	height: 50px;
	display: flex;
	justify-content: center;
	align-items:center;
	z-index: 100;
}
.myfootbtn{
	margin: 8px 5%;
	width: 90%;
}
</style>
